<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>用户管理</title>
	<meta name="decorator" content="default"/>
	<style type="text/css">
		.BoxDiv{
			position:fixed;
			padding-left:30px;
			padding-top:20px;
			width:400px;
			height:200px;
			background:#f5f5f5;
			top:10%;
			left:25%;
			margin:0 auto;
			border:1px solid #CCC;
			box-shadow:3px 3px 10px 4px #DDD;
		}
		.BoxDiv .ib_title{
			margin-bottom:35px;
		}
	</style>
	<script type="text/javascript">
		$(document).ready(function() {
			$("#returnMoneyForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				rules:{
					money:{required:true,number:true,min:0.01,minNumber:true},
					remarks:{maxlength:20}
				},
				messages:{
					money:{
						required:"请输入还款金额",
						number:"请输入正确金额",
						min: "输入最小金额为0.01"
					},
					remarks:{maxlength:"不能超过20字"}
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element.parent());
					}
				}
			});
			$("#deductMoneyForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				rules:{
					money:{required:true,number:true,min:0.01,minNumber:true},
					remarks:{maxlength:20}
				},
				messages:{
					money:{
						required:"请输入还款金额",
						number:"请输入正确金额",
						min: "输入最小金额为0.01"
					},
					remarks:{maxlength:"不能超过20字"}
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element.parent());
					}
				}
			});
			jQuery.validator.addMethod("minNumber",function(value, element){
				var returnVal = true;
				inputZ=value;
				var ArrMen= inputZ.split(".");    //截取字符串
				if(ArrMen.length==2){
					if(ArrMen[1].length>2){    //判断小数点后面的字符串长度
	                    returnVal = false;
	                    return false;
	                }
	            }
	            return returnVal;
			},"小数点后最多为两位"); 
		});
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
		//还款
		function returnMoneyDivOpen(){
			$("#returnMoneyDiv").show();
		}
		function returnMoneyDivClose(){
			$("#returnMoneyDiv").hide();
		}
		//扣款
		function deductMoneyDivOpen(){
			$("#deductMoneyDiv").show();
		}
		function deductMoneyDivClose(){
			$("#deductMoneyDiv").hide();
		}
		function resetFunc(){
			$("#searchForm input[type='text']").val("");
			$('#s2id_type').find('.select2-chosen').html('所有 ');
			$("#type").find("option")[0].selected='selected';
		}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/sys/commonUser/vipUserInfoList">会员信息设置</a></li>
		<li><a href="${ctx}/sys/commonUser/creditLine?id=${user.id}">信用额度设置</a></li>
		<li class="active"><a href="${ctx}/sys/commonUser/transactionHistoryShow?userId=${user.id}">交易历史记录</a></li>
	</ul>
	<form:form id="searchForm" modelAttribute="yongUser" action="${ctx}/sys/commonUser/transactionHistoryShow?userId=${user.id }" method="post" class="breadcrumb form-search">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<ul class="ul-form">
			<li>
				<label style="width:50px;">日期：</label>
				<input name="startTime" type="text" placeholder="开始时间" readonly="readonly" class="input-medium Wdate " 
			         value="<fmt:formatDate  value="${transactionHistory.startTime }" pattern="yyyy-MM-dd HH:mm:ss"/>"
			         onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:true});"/>
			     -
			     <input name="endTime" type="text" placeholder="结束时间" readonly="readonly" class="input-medium Wdate " 
				     value="<fmt:formatDate  value="${transactionHistory.endTime }" pattern="yyyy-MM-dd HH:mm:ss"/>"
				     onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:true});"/> 
			</li>
			<li>
				<label>交易类型：</label>
				<form:select id="type" path="type" class="input-medium">
			    <form:option value="" label="所有"/>
			    <form:options items="${fns:getDictList('transaction_type')}" htmlEscape="false" itemValue="value" itemLabel="label"/>
			    </form:select>
			</li>
			<li class="btns"><input id="btnSubmit" class="btn btn-primary" type="submit" value="搜索"/></li>
			<li class="btns"><input class="btn btn-primary" type="button" value="重置" onclick="resetFunc()"/></li>
			<li class="btns"><a class="btn btn-primary" onclick="returnMoneyDivOpen()">还款</a></li>
			<li class="btns"><a class="btn btn-primary" onclick="deductMoneyDivOpen()">扣款</a></li>
			<li class="clearfix"></li>
		</ul>
	</form:form>
	<div style="display:none;">
			<sys:message content="${message}"/>
	</div>
	<table class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
				<th>交易类型</th>
				<th>日期</th>
				<th>交易编号</th>
				<th>说明</th>
				<th>金额</th>
			</tr>
		</thead>
		<tbody>
		<c:if test="${empty page.list}">
				<tr>
				<td colspan="5">暂无记录</td>
				</tr>
			</c:if>
			<c:if test="${not empty page.list}">
			<c:forEach items="${page.list}" var="transactionHistory">
				<tr>
					<td>${fns:getDictLabel(transactionHistory.type, 'transaction_type', '')}</td>
					<td><fmt:formatDate value="${transactionHistory.createDate}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
					<c:choose>
					<c:when test="${transactionHistory.type==1}">
						<td><a href="${ctx}/sys/orders/form?id=${orders.id}&tagUrl=${ctx}/sys/commonUser/transactionHistoryShow&tagName=交易历史记录">${transactionHistory.code }</a></td>
					</c:when>
					<c:when test="${transactionHistory.type==4}">
						<td><a href="${ctx}/sys/orders/form?id=${orders.id}&tagUrl=${ctx}/sys/commonUser/transactionHistoryShow&tagName=交易历史记录">${transactionHistory.code }</a></td>
					</c:when>
					<c:otherwise>
						<td>${transactionHistory.code }</td>
					</c:otherwise>
					</c:choose>
					<td>${transactionHistory.remarks }</td>
					<td>￥${transactionHistory.money }</td>
				</tr>
			</c:forEach>
			</c:if>
		</tbody>
	</table>
	<div class="pagination">${page}</div>
	<div id="returnMoneyDiv" class="hide BoxDiv">
		<form id="returnMoneyForm" action="${ctx}/sys/commonUser/returnMoneySave" class="breadcrumb form-search checkForm" >
			<input type="hidden" name="userId" value="${user.id }"> 
			<div class="control-group">
				<label class="control-label">请输入金额：<input type="text" name="money" class="input-medium"/><span>元</span></label>
			</div>
			<div class="control-group">
				<input type="radio" name="type" value="3" checked="checked"/>还款补录
			</div>
			<div class="control-group">
				<input type="radio" name="type" value="7"/>其他<input type="text" name="remarks"/>
			</div>
			<div class="control-group">
				<div class="controls">
				<input type="submit" value="确定" class="btn btn-primary">
				<input type="button" value="取消" class="btn btn-primary" onclick="returnMoneyDivClose()">
				</div>
			</div>
		</form>
	</div>
	<div id="deductMoneyDiv" class="hide BoxDiv">
		<form id="deductMoneyForm" action="${ctx}/sys/commonUser/deductMoneySave" class="breadcrumb form-search checkForm" >
			<input type="hidden" name="userId" value="${user.id }"> 
			<div class="control-group">
				<label class="control-label">请输入金额：<input type="text" name="money" class="input-medium"/><span>元</span></label>
			</div>
			<div class="control-group">
				<input type="radio" name="type" value="7" checked="checked"/>其他<input type="text" name="remarks"/>
			</div>
			<div class="control-group">
				<div class="controls">
				<input type="submit" value="确定" class="btn btn-primary">
				<input type="button" value="取消" class="btn btn-primary" onclick="deductMoneyDivClose()">
				</div>
			</div>
		</form>
	</div>
</body>
</html>